package biz

import (
    "context"

    "github.com/go-kratos/kratos/v2/log"
    "mall/app/product/internal/domain"
)

type ProductRepo interface {
    Create(ctx context.Context, product *domain.Product) (*domain.Product, error)
    List(ctx context.Context, req *domain.ListReq) (*domain.ListResp, error)
    Detail(ctx context.Context, id uint) (*domain.Product, error)
    Edit(ctx context.Context, id uint, product *domain.Product) (*domain.Product, error)
    AddStock(ctx context.Context, id uint, num int) (*domain.Product, error)
}

type ProductUseCase struct {
    repo ProductRepo
    log  *log.Helper
}

func NewProductUseCase(repo ProductRepo, logger log.Logger) *ProductUseCase {
    return &ProductUseCase{
        repo: repo,
        log:  log.NewHelper(log.With(logger, "module", "use-case/product")),
    }
}

func (uc *ProductUseCase) Create(ctx context.Context, product *domain.Product) (*domain.Product, error) {
    return uc.repo.Create(ctx, product)
}

func (uc *ProductUseCase) List(ctx context.Context, req *domain.ListReq) (*domain.ListResp, error) {
    return uc.repo.List(ctx, req)
}

func (uc *ProductUseCase) Detail(ctx context.Context, id uint) (*domain.Product, error) {
    return uc.repo.Detail(ctx, id)
}

func (uc *ProductUseCase) Edit(ctx context.Context, id uint, product *domain.Product) (*domain.Product, error) {
    return uc.repo.Edit(ctx, id, product)
}

func (uc *ProductUseCase) AddStock(ctx context.Context, id uint, num int) (*domain.Product, error) {
    return uc.repo.AddStock(ctx, id, num)
}
